home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / CheckNameUniqueness.c < prev    next >
Text File  |  1994-08-15  |  8KB  |  258 lines

  1. /* CheckNameUniqueness.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "CheckNameUniqueness.h"
  31. #include "MainWindowStuff.h"
  32. #include "Memory.h"
  33. #include "SampleList.h"
  34. #include "AlgoSampList.h"
  35. #include "WaveTableList.h"
  36. #include "AlgoWaveTableList.h"
  37. #include "InstrList.h"
  38. #include "SampleObject.h"
  39. #include "AlgoSampObject.h"
  40. #include "WaveTableObject.h"
  41. #include "AlgoWaveTableObject.h"
  42. #include "InstrObject.h"
  43. #include "Array.h"
  44. #include "DataMunging.h"
  45. #include "Alert.h"
  46.  
  47.  
  48. static void                    CleanUpStringArray(ArrayRec* Array)
  49.     {
  50.         long                            Scan;
  51.         long                            Limit;
  52.  
  53.         CheckPtrExistence(Array);
  54.         Limit = ArrayGetLength(Array);
  55.         for (Scan = 0; Scan < Limit; Scan += 1)
  56.             {
  57.                 ReleasePtr((char*)ArrayGetElement(Array,Scan));
  58.             }
  59.         DisposeArray(Array);
  60.     }
  61.  
  62.  
  63. static MyBoolean        TestArrays(ArrayRec* Array)
  64.     {
  65.         long                            Limit;
  66.         long                            FirstScan;
  67.         long                            SecondScan;
  68.         char*                            Str1;
  69.         char*                            Str2;
  70.  
  71.         CheckPtrExistence(Array);
  72.         Limit = ArrayGetLength(Array);
  73.         FirstScan = 0;
  74.         while (FirstScan < Limit - 1)
  75.             {
  76.                 SecondScan = FirstScan + 1;
  77.                 while (SecondScan < Limit)
  78.                     {
  79.                         Str1 = (char*)ArrayGetElement(Array,FirstScan);
  80.                         Str2 = (char*)ArrayGetElement(Array,SecondScan);
  81.                         if (PtrSize(Str1) == PtrSize(Str2))
  82.                             {
  83.                                 if (MemEqu(Str1,Str2,PtrSize(Str1)))
  84.                                     {
  85.                                         return True; /* found a match */
  86.                                     }
  87.                             }
  88.                         SecondScan += 1;
  89.                     }
  90.                 FirstScan += 1;
  91.             }
  92.         return False; /* couldn't find a match */
  93.     }
  94.  
  95.  
  96. /* this checks all of the objects to make sure that names are unique */
  97. /* it returns True if they are, or returns False and presents a warning dialog */
  98. /* if they aren't unique */
  99. MyBoolean                        CheckNameUniqueness(struct MainWindowRec* MainWindow)
  100.     {
  101.         SampleListRec*                SampleList;
  102.         AlgoSampListRec*            AlgoSampList;
  103.         WaveTableListRec*            WaveTableList;
  104.         AlgoWaveTableListRec*    AlgoWaveTableList;
  105.         InstrListRec*                    InstrList;
  106.         ArrayRec*                            Array;
  107.         long                                    Scan;
  108.         long                                    Limit;
  109.         char*                                    StringTemp;
  110.         MyBoolean                            Result;
  111.  
  112.         CheckPtrExistence(MainWindow);
  113.  
  114.         SampleList = MainWindowGetSampleList(MainWindow);
  115.         CheckPtrExistence(SampleList);
  116.         AlgoSampList = MainWindowGetAlgoSampList(MainWindow);
  117.         CheckPtrExistence(AlgoSampList);
  118.  
  119.         WaveTableList = MainWindowGetWaveTableList(MainWindow);
  120.         CheckPtrExistence(WaveTableList);
  121.         AlgoWaveTableList = MainWindowGetAlgoWaveTableList(MainWindow);
  122.         CheckPtrExistence(AlgoWaveTableList);
  123.  
  124.         InstrList = MainWindowGetInstrList(MainWindow);
  125.         CheckPtrExistence(InstrList);
  126.  
  127.         Array = NewArray();
  128.         if (Array == NIL)
  129.             {
  130.              FailurePointA1:
  131.                 return True;
  132.             }
  133.         Limit = SampleListHowMany(SampleList);
  134.         for (Scan = 0; Scan < Limit; Scan += 1)
  135.             {
  136.                 StringTemp = SampleObjectGetNameCopy(SampleListGetIndexedSample(SampleList,Scan));
  137.                 if (StringTemp == NIL)
  138.                     {
  139.                      FailurePointA2a:
  140.                         CleanUpStringArray(Array);
  141.                         goto FailurePointA1;
  142.                     }
  143.                 if (!ArrayAppendElement(Array,StringTemp))
  144.                     {
  145.                      FailurePointA2b:
  146.                         ReleasePtr(StringTemp);
  147.                         goto FailurePointA2a;
  148.                     }
  149.             }
  150.         Limit = AlgoSampListHowMany(AlgoSampList);
  151.         for (Scan = 0; Scan < Limit; Scan += 1)
  152.             {
  153.                 StringTemp = AlgoSampObjectGetNameCopy(AlgoSampListGetIndexedAlgoSamp(
  154.                     AlgoSampList,Scan));
  155.                 if (StringTemp == NIL)
  156.                     {
  157.                      FailurePointA3a:
  158.                         goto FailurePointA2a;
  159.                     }
  160.                 if (!ArrayAppendElement(Array,StringTemp))
  161.                     {
  162.                      FailurePointA3b:
  163.                         ReleasePtr(StringTemp);
  164.                         goto FailurePointA3a;
  165.                     }
  166.             }
  167.         Result = TestArrays(Array);
  168.         CleanUpStringArray(Array);
  169.         if (Result)
  170.             {
  171.                 AlertHalt("Some samples or algorithmic samples have the same name.",NIL);
  172.                 return False; /* found a match */
  173.             }
  174.  
  175.         Array = NewArray();
  176.         if (Array == NIL)
  177.             {
  178.              FailurePointB1:
  179.                 return True;
  180.             }
  181.         Limit = WaveTableListHowMany(WaveTableList);
  182.         for (Scan = 0; Scan < Limit; Scan += 1)
  183.             {
  184.                 StringTemp = WaveTableObjectGetNameCopy(WaveTableListGetIndexedWaveTable(
  185.                     WaveTableList,Scan));
  186.                 if (StringTemp == NIL)
  187.                     {
  188.                      FailurePointB2a:
  189.                         CleanUpStringArray(Array);
  190.                         goto FailurePointB1;
  191.                     }
  192.                 if (!ArrayAppendElement(Array,StringTemp))
  193.                     {
  194.                      FailurePointB2b:
  195.                         ReleasePtr(StringTemp);
  196.                         goto FailurePointB2a;
  197.                     }
  198.             }
  199.         Limit = AlgoWaveTableListHowMany(AlgoWaveTableList);
  200.         for (Scan = 0; Scan < Limit; Scan += 1)
  201.             {
  202.                 StringTemp = AlgoWaveTableObjectGetNameCopy(
  203.                     AlgoWaveTableListGetIndexedAlgoWaveTable(AlgoWaveTableList,Scan));
  204.                 if (StringTemp == NIL)
  205.                     {
  206.                      FailurePointB3a:
  207.                         goto FailurePointB2a;
  208.                     }
  209.                 if (!ArrayAppendElement(Array,StringTemp))
  210.                     {
  211.                      FailurePointB3b:
  212.                         ReleasePtr(StringTemp);
  213.                         goto FailurePointB3a;
  214.                     }
  215.             }
  216.         Result = TestArrays(Array);
  217.         CleanUpStringArray(Array);
  218.         if (Result)
  219.             {
  220.                 AlertHalt("Some wave tables or algorithmic wave tables have the same name.",NIL);
  221.                 return False; /* found a match */
  222.             }
  223.  
  224.         Array = NewArray();
  225.         if (Array == NIL)
  226.             {
  227.              FailurePointC1:
  228.                 return True;
  229.             }
  230.         Limit = InstrListHowMany(InstrList);
  231.         for (Scan = 0; Scan < Limit; Scan += 1)
  232.             {
  233.                 StringTemp = InstrObjectGetNameCopy(InstrListGetIndexedInstr(
  234.                     InstrList,Scan));
  235.                 if (StringTemp == NIL)
  236.                     {
  237.                      FailurePointC2a:
  238.                         CleanUpStringArray(Array);
  239.                         goto FailurePointC1;
  240.                     }
  241.                 if (!ArrayAppendElement(Array,StringTemp))
  242.                     {
  243.                      FailurePointC2b:
  244.                         ReleasePtr(StringTemp);
  245.                         goto FailurePointC2a;
  246.                     }
  247.             }
  248.         Result = TestArrays(Array);
  249.         CleanUpStringArray(Array);
  250.         if (Result)
  251.             {
  252.                 AlertHalt("Some instruments have the same name.",NIL);
  253.                 return False; /* found a match */
  254.             }
  255.  
  256.         return True; /* everything's ok */
  257.     }
  258.